<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>CSS3系列（一） | Show Code</title><meta name="keywords" content="css3"><meta name="author" content="const name='LSF'"><meta name="copyright" content="const name='LSF'"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="CSS（cascading style sheet 层叠样式表）用来给HTML标签添加样式的语言 CSS3是最新的版本，新增大量样式，动画、3D特效和移动端特性  简介三大特性：  层叠性：小属性会层叠大属性 优先级：id&gt;class&gt;标签 继承性:属性具有继承的性质  CSS负责网站的样式，和HTML连接在一起使用的是选择器，语法大概是这样的 123选择器&amp;#123;属性：属性值;">
<meta property="og:type" content="article">
<meta property="og:title" content="CSS3系列（一）">
<meta property="og:url" content="https://www.frontblog.top/css3/index.html">
<meta property="og:site_name" content="Show Code">
<meta property="og:description" content="CSS（cascading style sheet 层叠样式表）用来给HTML标签添加样式的语言 CSS3是最新的版本，新增大量样式，动画、3D特效和移动端特性  简介三大特性：  层叠性：小属性会层叠大属性 优先级：id&gt;class&gt;标签 继承性:属性具有继承的性质  CSS负责网站的样式，和HTML连接在一起使用的是选择器，语法大概是这样的 123选择器&amp;#123;属性：属性值;">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://dss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=968859261,3896020000&fm=26&gp=0.jpg">
<meta property="article:published_time" content="2021-05-15T03:24:16.000Z">
<meta property="article:modified_time" content="2021-08-24T06:51:49.728Z">
<meta property="article:author" content="const name&#x3D;&#39;LSF&#39;">
<meta property="article:tag" content="css3">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://dss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=968859261,3896020000&fm=26&gp=0.jpg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://www.frontblog.top/css3/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//hm.baidu.com"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta name="baidu-site-verification" content="bca62aafa83c929047096bcb43c5ce68"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script async="async" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><script>(adsbygoogle = window.adsbygoogle || []).push({
  google_ad_client: 'ca-pub-7698107383427296',
  enable_page_level_ads: 'true'
});</script><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?bca62aafa83c929047096bcb43c5ce68";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-08-24 14:51:49'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    })(window)</script><meta name="generator" content="Hexo 5.4.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="/img/ls.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">21</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">19</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://dss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=968859261,3896020000&amp;fm=26&amp;gp=0.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">Show Code</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">CSS3系列（一）</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-05-15T03:24:16.000Z" title="发表于 2021-05-15 11:24:16">2021-05-15</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-08-24T06:51:49.728Z" title="更新于 2021-08-24 14:51:49">2021-08-24</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/CSS3/">CSS3</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><blockquote>
<p>CSS（cascading style sheet 层叠样式表）用来给HTML标签添加样式的语言</p>
<p>CSS3是最新的版本，新增大量样式，动画、3D特效和移动端特性</p>
</blockquote>
<h1 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h1><p>三大特性：</p>
<ul>
<li>层叠性：小属性会层叠大属性</li>
<li>优先级：id&gt;class&gt;标签</li>
<li>继承性:属性具有继承的性质</li>
</ul>
<p>CSS负责网站的样式，和HTML连接在一起使用的是选择器，语法大概是这样的</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">选择器&#123;</span><br><span class="line">属性：属性值;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="选择器"><a href="#选择器" class="headerlink" title="选择器"></a>选择器</h1><h2 id="CSS2-1"><a href="#CSS2-1" class="headerlink" title="CSS2.1"></a>CSS2.1</h2><ul>
<li><p>标签选择器</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">span</span>&#123;</span><br><span class="line"><span class="attribute">color</span>:red</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>也称为元素选择器，选择页面上所有该种标签，无论这个标签所处的位置深浅，覆盖面大</p>
</li>
<li><p>id选择器</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-id">#idname</span></span><br></pre></td></tr></table></figure>

<p>标签唯一值，不能数字开头</p>
</li>
<li><p>class选择器</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.classname</span></span><br></pre></td></tr></table></figure>

<p>不唯一，类选择器，选择指定标签的选择器</p>
</li>
<li><p>复合选择器</p>
<p>后代选择器：选择类名box标签内部所有spec标签</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.box</span> <span class="selector-class">.spec</span></span><br></pre></td></tr></table></figure>

<p>交集选择器：选择既是li又是spec类的标签 </p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">li</span><span class="selector-class">.spec</span></span><br></pre></td></tr></table></figure>

<p>并集选择器：选择所有ul和ol标签</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">ol</span>,<span class="selector-tag">ul</span></span><br></pre></td></tr></table></figure></li>
<li><p>伪类</p>
<p>指定要选择的元素的特殊状态，超级链接拥有4个特殊状态，要按顺序书写，否则不生效</p>
<table>
<thead>
<tr>
<th>伪类</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>link</td>
<td>没访问过的超级链接</td>
</tr>
<tr>
<td>visited</td>
<td>访问过的链接</td>
</tr>
<tr>
<td>hover</td>
<td>鼠标悬停</td>
</tr>
<tr>
<td>active</td>
<td>正在被激活，按下没松开</td>
</tr>
</tbody></table>
</li>
</ul>
<h2 id="CSS3"><a href="#CSS3" class="headerlink" title="CSS3"></a>CSS3</h2><ul>
<li><p>元素选择器</p>
<p>子选择器：指该标签下面的标签，可以类比后代选择器</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">div&gt;p</span><br></pre></td></tr></table></figure>

<p>相邻兄弟选择器：所有span紧跟着img的标签 </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">img+p</span><br></pre></td></tr></table></figure>

<p>通用兄弟选择器：P元素之后所有同层级span</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">p~span</span><br></pre></td></tr></table></figure></li>
<li><p>序号选择器(除了:first-child支持到IE7，其他都是IE9)</p>
<p>:first-child 第一个子元素 (IE7)</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-pseudo">:first</span>-child</span><br></pre></td></tr></table></figure>

<p>:last-child 最后一个子元素</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-pseudo">:last-child</span></span><br></pre></td></tr></table></figure>

<p>:nth-child(n)  第N个子元素  an+b表示b开始每a个选一个  2n+1等价odd  2n等价even</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-pseudo">:nth-child</span>(n)</span><br></pre></td></tr></table></figure>

<p>:nth-of-type(n)  第N个某类型子元素，表示这个类型的N个</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-pseudo">:nth-of-type</span>(n)</span><br></pre></td></tr></table></figure>

<p>:nth-last-child(n)  倒数第N个子元素</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-pseudo">:nth-last-child</span>(n)</span><br></pre></td></tr></table></figure>

<p>:nth-last-of-type(n)  倒数第N个某类型子元素</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-pseudo">:nth-last-of-type</span>(n)</span><br></pre></td></tr></table></figure></li>
<li><p>属性选择器</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">img[alt]</span><br></pre></td></tr></table></figure></li>
<li><p>新增伪类</p>
<p>empty：选择空标签，空格不算空标签 </p>
<p>focus：选择当前获得焦点的表单元素</p>
<p>enabled：选择当前有效的表单元素</p>
<p>disabled：选择当前无效的表单元素</p>
<p>checked：选择当前已经勾选的单选按钮或者复选框</p>
<p>root：选择根元素，html标签</p>
</li>
<li><p>伪元素</p>
<p><code>::before</code>：创建一个伪元素，其将成为匹配选中的元素的第一个子元素，必须设置content属性表示其中的内容</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">a</span><span class="selector-pseudo">::before</span>&#123;</span><br><span class="line"><span class="attribute">content</span>:<span class="string">&#x27;★&#x27;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><code>::after</code>：创建一个伪元素，其将成为匹配选中的元素的最后一个子元素，必须设置content属性表示其中的内容</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">a</span><span class="selector-pseudo">::after</span>&#123;</span><br><span class="line"><span class="attribute">content</span>:<span class="string">&#x27;★&#x27;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
</ul>
<p><code>::selection</code>：文档被用户高亮的部分，使用鼠标圈选部分</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.box</span><span class="selector-pseudo">::selection</span>&#123;</span><br><span class="line"><span class="attribute">color</span>:red</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><code>::first-letter</code>：文档第一行第一个字</p>
<p><code>::first-line</code>：文档第一行字</p>
<h2 id="层叠性和权重"><a href="#层叠性和权重" class="headerlink" title="层叠性和权重"></a>层叠性和权重</h2><p>冲突处理：ID&gt;Class&gt;标签</p>
<p>复杂选择器可以通过：ID个数、class个数、标签个数</p>
<h1 id="文与字体属性"><a href="#文与字体属性" class="headerlink" title="文与字体属性"></a>文与字体属性</h1><h2 id="常用的文本属性"><a href="#常用的文本属性" class="headerlink" title="常用的文本属性"></a>常用的文本属性</h2><ul>
<li><p>color属性：</p>
<p>文本颜色前景色，十六进制表示法，英文表示法，rgb表示法，rgba（</p>
</li>
<li><p>font-size属性</p>
<p>设置字号，默认16px，最小16px</p>
</li>
<li><p>font-weight属性</p>
<p>px为单位，4个属性值：</p>
<p>normal：正常粗细，400等值</p>
<p>bold：加粗，700等值</p>
<p>lighter：更细，多数中文不支持</p>
<p>bolder：更粗，多数中文不支持</p>
</li>
<li><p>font-style属性</p>
<p>3个属性值：</p>
<p>normal：正常</p>
<p>italic：倾斜（常用）</p>
<p>oblique：倾斜（不常用）</p>
</li>
</ul>
<h2 id="文本属性详解"><a href="#文本属性详解" class="headerlink" title="文本属性详解"></a>文本属性详解</h2><ul>
<li><p>font-family属性</p>
<p>设置字体，后面的字体是备用字体，@font-face定义字体</p>
</li>
</ul>
<h2 id="段落和行问题属性"><a href="#段落和行问题属性" class="headerlink" title="段落和行问题属性"></a>段落和行问题属性</h2><ul>
<li><p>text-inddent属性</p>
<p>定义首行文本内容之前的缩进量，单位为em，一般是不用空格去做首行的缩进的</p>
</li>
<li><p>line-height属性</p>
<p>定义行高，行高等于盒子高就是垂直居中，单位可以px，倍数，百分数</p>
</li>
<li><p>text-align属性</p>
<p>定义文本水平居中</p>
</li>
</ul>
<h1 id="继承性"><a href="#继承性" class="headerlink" title="继承性"></a>继承性</h1><p>文本相关属性普遍具有继承性，在继承情况下，<strong>选择器的权重计算会失效，而是”就近原则“</strong></p>
<h1 id="盒模型"><a href="#盒模型" class="headerlink" title="盒模型"></a>盒模型</h1><h2 id="认识盒模型"><a href="#认识盒模型" class="headerlink" title="认识盒模型"></a>认识盒模型</h2><p>由width、height、padding、border构成，成为盒模型，width、height是内容的长度，border是边框，padding是内边距</p>
<h2 id="padding属性"><a href="#padding属性" class="headerlink" title="padding属性"></a>padding属性</h2><p>内边距，文字到边框内壁的距离就是padding，四个方是：上右下左，三个方向是：上左右下，两个方向：上下左右</p>
<p>padding默认是外扩的，padding越大，盒子的总宽度就会越大</p>
<h2 id="margin属性"><a href="#margin属性" class="headerlink" title="margin属性"></a>margin属性</h2><p>外边距，盒子和盒子的距离，四个方向属性</p>
<p><strong>竖直的margin会塌陷</strong>，小的会塌陷到大的，左右没有塌陷，可以叠加</p>
<p>一些元素有默认的margin</p>
<p>盒子水平居中：margin：0 auto</p>
<h2 id="盒模型计算"><a href="#盒模型计算" class="headerlink" title="盒模型计算"></a>盒模型计算</h2><p>现在有一个盒子：</p>
<p><img src="/css3/fuhezi.png"></p>
<p>盒子实际的宽度：400+10+10+6+6 = 432px</p>
<p>盒子实际的高度：300+10+10+6+6 = 332px</p>
<h2 id="box-sizing属性"><a href="#box-sizing属性" class="headerlink" title="box-sizing属性"></a>box-sizing属性</h2><p>将盒子添加：box-sizing：border-box之后，盒子的宽高就是实际宽高，把padding、border变为内缩，适合 移动网页，兼容IE9</p>
<h2 id="dislay属性"><a href="#dislay属性" class="headerlink" title="dislay属性"></a>dislay属性</h2><p>3个属性值：</p>
<p>block：转为块级元素</p>
<p>inline：转为行内元素</p>
<p>inline-block：行内块</p>
<h2 id="元素隐藏"><a href="#元素隐藏" class="headerlink" title="元素隐藏"></a>元素隐藏</h2><p><code>dislay:none</code>：隐藏，放弃位置</p>
<p><code>visibility:hidden</code>：隐藏，不放弃位置</p>
<h1 id="浮动与定位"><a href="#浮动与定位" class="headerlink" title="浮动与定位"></a>浮动与定位</h1><h2 id="浮动"><a href="#浮动" class="headerlink" title="浮动"></a>浮动</h2><h3 id="概念"><a href="#概念" class="headerlink" title="概念"></a>概念</h3><p><strong>最本质的功能</strong>：就是用来实现并排</p>
<p><strong>实现要点：</strong>子盒子要浮动都浮动，父盒子要有足够宽度，否则会掉下去</p>
<p><strong>关键字：</strong>float</p>
<p><strong>浮动的顺序贴靠：</strong>如果没有足够空间，则会寻找 再前一个兄弟元素</p>
<p><strong>浮动之后不管是行内还是块级，都是可以设置宽高</strong></p>
<h3 id="网页布局"><a href="#网页布局" class="headerlink" title="网页布局"></a>网页布局</h3><p><img src="/css3/buju.png"></p>
<p><strong>注意事项</strong>：</p>
<p>垂直盒子不要设置浮动，本质上浮动就是实现并排的，垂直的盒子，默认就是垂直，而且浮动只有左右浮动，存在高度塌陷问题，这是一种比较老旧的网页布局解决方案</p>
<p>大盒子带着小盒子跑，大盒子浮动，里面的小盒子就已经被大盒子跑了，这不是继承关系</p>
<h3 id="BFC规范和浏览器差异"><a href="#BFC规范和浏览器差异" class="headerlink" title="BFC规范和浏览器差异"></a>BFC规范和浏览器差异</h3><p>没有BFC：一个盒子不设置高度，单子元素浮动时，无法撑起自身</p>
<h1 id="边框与圆角"><a href="#边框与圆角" class="headerlink" title="边框与圆角"></a>边框与圆角</h1><h1 id="背景"><a href="#背景" class="headerlink" title="背景"></a>背景</h1><h1 id="变形"><a href="#变形" class="headerlink" title="变形"></a>变形</h1><h1 id="过渡与动画"><a href="#过渡与动画" class="headerlink" title="过渡与动画"></a>过渡与动画</h1></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined" rel="external nofollow noreferrer">const name='LSF'</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://www.frontblog.top/css3/">https://www.frontblog.top/css3/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow noreferrer" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://www.frontblog.top" target="_blank">Show Code</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/css3/">css3</a></div><div class="post_share"><div class="social-share" data-image="https://dss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=968859261,3896020000&amp;fm=26&amp;gp=0.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button button--animated"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/img/wechat.jpg" target="_blank"><img class="post-qr-code-img" src="/img/wechat.jpg" alt="wechat"/></a><div class="post-qr-code-desc">wechat</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/wxbug/"><img class="prev-cover" src="https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=603789532,900152941&amp;fm=26&amp;gp=0.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">使用SVG自定义tabbar的坑</div></div></a></div><div class="next-post pull-right"><a href="/bug/"><img class="next-cover" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Svg转Base64的坑</div></div></a></div></nav><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" src="/img/ls.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">const name='LSF'</div><div class="author-info__description">人生就像品茶，懂得吃苦，才能回甘啊。</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">21</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">19</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener external nofollow noreferrer" href="https://gitee.com/lsfcxz"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitee.com/lsfcxz" rel="external nofollow noreferrer" target="_blank" title="Gitee"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:1770813141@qq.com" rel="external nofollow noreferrer" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">人生就像品茶，懂得吃苦，才能回甘啊。</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E7%AE%80%E4%BB%8B"><span class="toc-number">1.</span> <span class="toc-text">简介</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E9%80%89%E6%8B%A9%E5%99%A8"><span class="toc-number">2.</span> <span class="toc-text">选择器</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#CSS2-1"><span class="toc-number">2.1.</span> <span class="toc-text">CSS2.1</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#CSS3"><span class="toc-number">2.2.</span> <span class="toc-text">CSS3</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B1%82%E5%8F%A0%E6%80%A7%E5%92%8C%E6%9D%83%E9%87%8D"><span class="toc-number">2.3.</span> <span class="toc-text">层叠性和权重</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%96%87%E4%B8%8E%E5%AD%97%E4%BD%93%E5%B1%9E%E6%80%A7"><span class="toc-number">3.</span> <span class="toc-text">文与字体属性</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B8%B8%E7%94%A8%E7%9A%84%E6%96%87%E6%9C%AC%E5%B1%9E%E6%80%A7"><span class="toc-number">3.1.</span> <span class="toc-text">常用的文本属性</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%96%87%E6%9C%AC%E5%B1%9E%E6%80%A7%E8%AF%A6%E8%A7%A3"><span class="toc-number">3.2.</span> <span class="toc-text">文本属性详解</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%AE%B5%E8%90%BD%E5%92%8C%E8%A1%8C%E9%97%AE%E9%A2%98%E5%B1%9E%E6%80%A7"><span class="toc-number">3.3.</span> <span class="toc-text">段落和行问题属性</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E7%BB%A7%E6%89%BF%E6%80%A7"><span class="toc-number">4.</span> <span class="toc-text">继承性</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E7%9B%92%E6%A8%A1%E5%9E%8B"><span class="toc-number">5.</span> <span class="toc-text">盒模型</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%AE%A4%E8%AF%86%E7%9B%92%E6%A8%A1%E5%9E%8B"><span class="toc-number">5.1.</span> <span class="toc-text">认识盒模型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#padding%E5%B1%9E%E6%80%A7"><span class="toc-number">5.2.</span> <span class="toc-text">padding属性</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#margin%E5%B1%9E%E6%80%A7"><span class="toc-number">5.3.</span> <span class="toc-text">margin属性</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%9B%92%E6%A8%A1%E5%9E%8B%E8%AE%A1%E7%AE%97"><span class="toc-number">5.4.</span> <span class="toc-text">盒模型计算</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#box-sizing%E5%B1%9E%E6%80%A7"><span class="toc-number">5.5.</span> <span class="toc-text">box-sizing属性</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#dislay%E5%B1%9E%E6%80%A7"><span class="toc-number">5.6.</span> <span class="toc-text">dislay属性</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%85%83%E7%B4%A0%E9%9A%90%E8%97%8F"><span class="toc-number">5.7.</span> <span class="toc-text">元素隐藏</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%B5%AE%E5%8A%A8%E4%B8%8E%E5%AE%9A%E4%BD%8D"><span class="toc-number">6.</span> <span class="toc-text">浮动与定位</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B5%AE%E5%8A%A8"><span class="toc-number">6.1.</span> <span class="toc-text">浮动</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%A6%82%E5%BF%B5"><span class="toc-number">6.1.1.</span> <span class="toc-text">概念</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BD%91%E9%A1%B5%E5%B8%83%E5%B1%80"><span class="toc-number">6.1.2.</span> <span class="toc-text">网页布局</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#BFC%E8%A7%84%E8%8C%83%E5%92%8C%E6%B5%8F%E8%A7%88%E5%99%A8%E5%B7%AE%E5%BC%82"><span class="toc-number">6.1.3.</span> <span class="toc-text">BFC规范和浏览器差异</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%BE%B9%E6%A1%86%E4%B8%8E%E5%9C%86%E8%A7%92"><span class="toc-number">7.</span> <span class="toc-text">边框与圆角</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%83%8C%E6%99%AF"><span class="toc-number">8.</span> <span class="toc-text">背景</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%8F%98%E5%BD%A2"><span class="toc-number">9.</span> <span class="toc-text">变形</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%BF%87%E6%B8%A1%E4%B8%8E%E5%8A%A8%E7%94%BB"><span class="toc-number">10.</span> <span class="toc-text">过渡与动画</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/CSSMedia/" title="CSS3媒体查询"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="CSS3媒体查询"/></a><div class="content"><a class="title" href="/CSSMedia/" title="CSS3媒体查询">CSS3媒体查询</a><time datetime="2021-08-24T06:54:22.000Z" title="发表于 2021-08-24 14:54:22">2021-08-24</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/mongodb/" title="使用Docker方式安装mongodb数据库"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="使用Docker方式安装mongodb数据库"/></a><div class="content"><a class="title" href="/mongodb/" title="使用Docker方式安装mongodb数据库">使用Docker方式安装mongodb数据库</a><time datetime="2021-07-12T12:21:57.000Z" title="发表于 2021-07-12 20:21:57">2021-07-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/cicd/" title="实现CICD平台"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="实现CICD平台"/></a><div class="content"><a class="title" href="/cicd/" title="实现CICD平台">实现CICD平台</a><time datetime="2021-07-12T10:14:05.000Z" title="发表于 2021-07-12 18:14:05">2021-07-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/nosql/" title="NoSQL设计"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="NoSQL设计"/></a><div class="content"><a class="title" href="/nosql/" title="NoSQL设计">NoSQL设计</a><time datetime="2021-07-12T08:07:59.000Z" title="发表于 2021-07-12 16:07:59">2021-07-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/email/" title="阿里云邮箱配置问题"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="阿里云邮箱配置问题"/></a><div class="content"><a class="title" href="/email/" title="阿里云邮箱配置问题">阿里云邮箱配置问题</a><time datetime="2021-07-11T15:36:07.000Z" title="发表于 2021-07-11 23:36:07">2021-07-11</time></div></div></div></div><div class="card-widget ads-wrap"><script data-ad-client="ca-pub-7698107383427296" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script></div></div></div></main><footer id="footer" style="background-image: url('https://dss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=968859261,3896020000&amp;fm=26&amp;gp=0.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2021 By const name='LSF'</div><div class="footer_custom_text"><a target="_blank" rel="noopener external nofollow noreferrer" href="https://beian.miit.gov.cn/"><img class="icp-icon" src="/img/icp.png"><span>粤ICP备2021029106号</span></a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="chat_btn" type="button" title="rightside.chat_btn"><i class="fas fa-sms"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/search/local-search.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>function loadValine () {
  function initValine () {
    let initData = {
      el: '#vcomment',
      appId: 'w6Gw4UqYW4lsKyVlK45T98xo-gzGzoHsz',
      appKey: '9hvrOAKzIWScQU8OSxWiO5L0',
      placeholder: '記得留下你的暱稱和郵箱....可以快速收到回復',
      avatar: 'monsterid',
      meta: 'nick,mail,link'.split(','),
      pageSize: '10',
      lang: 'zh-CN',
      recordIP: false,
      serverURLs: '',
      emojiCDN: '',
      emojiMaps: "",
      enableQQ: false,
      path: window.location.pathname,
    }

    if (true) { 
      initData.requiredFields= ('nick,mail'.split(','))
    }
    
    if (false) {
      const otherData = false
      initData = Object.assign(initData, otherData)
    }
    
    const valine = new Valine(initData)
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !false) {
  if (false) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="99" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-nest.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script async data-pjax src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>